from rest_framework import serializers

from users.models import User
from .models import Question, Anwser, Label


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ["username"]


class LabelSerializer(serializers.ModelSerializer):
    class Meta:
        model = Label
        fields = ["name"]


class QuestionAllSerializer(serializers.ModelSerializer):
    user = UserSerializer()
    label = LabelSerializer()

    class Meta:
        model = Question
        fields = ["title", "user", "create_time", "browsing_volume", "label"]


class AnwserAllSerializer(serializers.ModelSerializer):
    user = UserSerializer()
    question = QuestionAllSerializer()

    class Meta:
        model = Anwser
        fields = ["user", "create_time", "question"]


class QuestionSerializer(serializers.ModelSerializer):
    user = UserSerializer()
    label = LabelSerializer()

    class Meta:
        model = Question
        fields = ["title", "user", "create_time", "browsing_volume", "label", "desc"]


class AnwserSerializer(serializers.ModelSerializer):
    user = UserSerializer()
    question = QuestionSerializer()

    class Meta:
        model = Anwser
        fields = ["user", "create_time", "question", "desc", "is_delete", "like"]









#
# # 问答详情
# class QuestionDetailSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Question
#         anwser = AnwserSerializer()
#         label = LabelSerializer()
#         fields = ["id", "title", "user", "create_time", "anwser", label]
#
#
# # 问答首页
# class QuestionListSerializer(serializers.ModelSerializer):
#     class Meta:
#         model = Question
#         anwser = AnwserSerializer()
#         fields = ["id", "title, "user", "create_time"]


